package com.viewsky.base.back.config;

import org.springframework.context.annotation.Configuration;

import com.viewsky.base.back.util.Constant;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;

@Configuration
public class LogFilterConfig extends Filter<ILoggingEvent>
{	
	@Override
	public FilterReply decide(ILoggingEvent event)
	{
		FilterReply reply = FilterReply.DENY;
		
		String strLoggerName = event.getLoggerName();
		if(strLoggerName != null)
		{
			/* 只记录程序包下的日志记录 */
			if(strLoggerName.startsWith(Constant.DEF_BASE_PACKAGE))
			{
				reply = FilterReply.ACCEPT;
			}
			else if(strLoggerName.startsWith(Constant.DEF_APACHE_CONTAINER_BASE) &&
					event.getLevel() == Level.ERROR)
			{
				reply = FilterReply.ACCEPT;
			}		
		}

		return reply;
	}
}
